package com.atguigu.gulimall.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class Cart {
    private Integer countNum;
    private Integer countType;
    private BigDecimal totalAmount;
    private BigDecimal reduce=new BigDecimal(0);
    private List<CartItem> items;

    public Integer getCountNum() {
        int cnt=0;
        if(items!=null&&items.size()>0){
            for (CartItem item : items) {
                cnt+=item.getCount();
            }
        }
        return cnt;
    }

    public Integer getCountType() {
        int cnt=0;
        if(items!=null&&items.size()>0){
            cnt= items.size();
        }
        return cnt;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal amount=new BigDecimal(0);
        if(items!=null&&items.size()>0){
            for (CartItem item : items) {
                if(item.getCheck()) {
                    amount = amount.add(item.getTotalPrice());
                }
            }
        }
        return amount.subtract(getReduce());
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }
}
